<?php

declare(strict_types=1);

namespace App\Robot\Amqp\Consumer;

use App\CustHub\Constants\ContactTaskCenterStatusConstants;
use App\CustHub\Constants\ContactTaskCenterTyperConstants;
use App\CustHub\Model\ChContact;
use App\CustHub\Model\ChContactTaskCenter;
use App\CustHub\Service\ChContactService;
use App\CustHub\Service\ChSmartAutoPushService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use Hyperf\Coroutine\Coroutine;
use PhpAmqpLib\Message\AMQPMessage;
use function Hyperf\Coroutine\co;

#[Consumer(exchange:"common_task_center", routingKey:"common_task_center", queue:"common_task_center", name:"commonTaskCenter", nums:1)]
class CommonTaskCenterConsumer extends ConsumerMessage
{
    public function consumeMessage($data, AMQPMessage $message): Result
    {
        stdout_log()->info('任务中心消费者开始执行任务...'.json_encode($data));
        if(empty($data['classname']) || empty($data['method']) || empty($data['data'])){
            return Result::ACK;
        }
        container()->get($data['classname'])->{$data['method']}($data['data']);
        return Result::ACK;
    }


    public function isEnable(): bool
    {
        return \Hyperf\Support\env('AMQP_CONSUMER_ENABLE',false);
    }
}